package com.example.park2212

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.lib_base.mvvm.BaseViewActivity
import com.example.park2212.databinding.ActivitySplashBinding
import java.util.Timer
import kotlin.concurrent.schedule
import kotlin.concurrent.timerTask

class SplashActivity : BaseViewActivity<ActivitySplashBinding>() {
    var timer:Timer?=null
    var time = 5

    override fun initView() {
        if (SPUtils.getInstance().getBoolean("isIn",false)){
            ARouter.getInstance().build( "/app/user/LoginActivity").navigation()
            finish()
        }
        timer = Timer()
        timer!!.schedule(timerTask {
            runOnUiThread {
                binding.splashTime.setText("${time}s")
                if (time == 0){
                    start()
                }
            }
            time--
        },0,1000)

        binding.splashTime.setOnClickListener {
           start()
        }
    }

    fun start() {
        SPUtils.getInstance().put("isIn",true)
        timer!!.cancel()
        ARouter.getInstance().build( "/app/user/LoginActivity").navigation()
        finish()
    }

    override fun initData() {

    }

    override fun onDestroy() {
        super.onDestroy()
        if (timer != null){
            timer!!.cancel()
            timer = null
        }
    }

}